//
//  IGMenuView.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/27.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "IGMenuView.h"
#import "TabItem.h"
@implementation IGMenuView

- (NSDictionary *)items {
    
    if (!_items) {
        
        if ([AppManager sharedManager].hasTicket) {
            
            _items = @{
                       @"view":@{@"title":@"HOMEPAGE_SITE",@"imageName":@"sightseeing",@"selectedNum":@(ScenicItem)},
                       @"line":@{@"title":@"HOMEPAGE_CITYTOUR",@"imageName":@"urbanline",@"selectedNum":@(CityTourItem)},
                       @"guide":@{@"title":@"HOMEPAGE_GUIDER",@"imageName":@"tourguide",@"selectedNum":@(GuiderItem)}, @"tickets":@{@"title":@"SITELIST_TICKET",@"imageName":@"tickets",@"selectedNum":@(TicketsItem)},
                       @"strategy":@{@"title":@"HOMEPAGE_STRATEGY",@"imageName":@"推荐行程",@"selectedNum":@(RaidersItem)},
                       @"map":@{@"title":@"HOMEPAGE_MAP",@"imageName":@"mapIcon",@"selectedNum":@(MapItem)},
                       @"business":@{@"title":@"HOMEPAGE_BUSINESS",@"imageName":@"商户",@"selectedNum":@(BusinessItem)}
                       };
        } else {
            
            _items = @{
                       @"view":@{@"title":@"HOMEPAGE_SITE",@"imageName":@"sightseeing",@"selectedNum":@(ScenicItem)},
                       @"line":@{@"title":@"HOMEPAGE_CITYTOUR",@"imageName":@"urbanline",@"selectedNum":@(CityTourItem)},
                       @"guide":@{@"title":@"HOMEPAGE_GUIDER",@"imageName":@"tourguide",@"selectedNum":@(GuiderItem)},
                       @"strategy":@{@"title":@"HOMEPAGE_STRATEGY",@"imageName":@"推荐行程",@"selectedNum":@(RaidersItem)},
                       @"map":@{@"title":@"HOMEPAGE_MAP",@"imageName":@"mapIcon",@"selectedNum":@(MapItem)},
                       @"business":@{@"title":@"HOMEPAGE_BUSINESS",@"imageName":@"商户",@"selectedNum":@(BusinessItem)}
                       };
        }
    }
    return _items;
}

- (void)setTabArray:(NSArray *)tabArray {
    
    if (self.subviews.count > 0) {
        for (UIView * view in self.subviews) {
            
            [view removeFromSuperview];
        }
    }
    CGFloat space = (kScreenWidth - (4.5 * 60))/ 5;
    
    NSInteger count = 0;
    for (int i= 0; i < tabArray.count; i++) {
        NSDictionary *dict = self.items[tabArray[i]];
        
        if (dict.count > 0) {
            
            TabItem * item = [TabItem initTabItemWith:dict];
            item.Ratio = 0.9;
            CGFloat X = space + count * (60 + space);
            item.frame = CGRectMake(X,15,54, 54 * 4/3);
            item.selectNum = [dict[@"selectedNum"] integerValue];
            [item addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:item];
            
            count ++;
        }
        
    }
    
    self.contentSize = CGSizeMake((space +60)*count + space , 0);
}

- (void)selectedItem:(TabItem *)item {
    
    if (self.igDelegate && [self.igDelegate respondsToSelector:@selector(selecteItem:)]) {
        
        [self.igDelegate selecteItem:item.selectNum];
    }
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end


